package MaintMenu.SyncInventoryToCat;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created with IntelliJ IDEA.
 * User: Jason
 * Date: 7/10/13
 * Time: 11:57 AM
 * To change this template use File | Settings | File Templates.
 */
public class AlterColumnType {

    public AlterColumnType(String table, String column, String newType){

        try {
            //DnkFunctions dnk = new DnkFunctions();
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbli";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement st = con.createStatement();

            try {


                st.executeUpdate("ALTER TABLE "+ table +" ALTER COLUMN "+column+" "+newType+";");


            }
            catch(SQLException er) {
                er.printStackTrace();
                System.out.println(er);
            }

            st.close();

            con.close();
        }
        catch(Exception e) {
            e.printStackTrace();
            System.out.println(e);
        }
    }
}
